package yxy.game.pm2.active.handle;

import org.joda.time.DateTime;
import yxy.apple.logger.Logger;
import yxy.game.pm2.active.module.ActiveModule_兑换码;
import yxy.game.pm2.bean.Currency;

import java.util.ArrayList;

public class Act_RedeemCodeHandle {

	private static final Logger logger = Logger.create(Act_RedeemCodeHandle.class);
	
	/**
	 * 
	 * @param rewards	奖励组
	 * @param num		数量
	 * @param redeemtype	兑换码类型
	 * @param losetime		失效时间
	 * @param name			兑换码名称
	 * @return
	 */
	public ArrayList<String> 兑换码(ArrayList<Currency> rewards, int num, int redeemtype, DateTime losetime, String name) {
		ArrayList<String> rcodes = new ArrayList<String>();
		
		//批次
		String batch = ActiveModule_兑换码.createbatch();
		
		ActiveModule_兑换码 am = new ActiveModule_兑换码();
		am.setRedeemtype(redeemtype);
		am.setBatch(batch);
		am.setLosetime(losetime.withHourOfDay(23).withMinuteOfHour(30).withSecondOfMinute(0).withMillisOfSecond(0));
		am.setName(name);
		am.setPcodes(new ArrayList<String>());
		am.setState(ActiveModule_兑换码.effective);
		am.setCurs(rewards);
		
		
		for(int i = 0; i < num; i++) {
			String redeemcode = ActiveModule_兑换码.createredeemcode();
			am.setRedeemcode(redeemcode);
			am.set();
			rcodes.add(am.getRedeemcode());
		}
		
		logger.info("名称：" + name + "数量：" + num + " |" + rcodes);
		return rcodes;
	}
}
